--
-- Author: yawei.zhu
-- Date: 2018-09-11 11:06:56
--
-- DynastyBattleHeadRender
--
local AvatarIconNode = require("app.widget.AvatarIconNode")

local ClassRef = app.mvc.createRenderClass(...)

--data =
function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.DynastyBattleHeadItem))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

--
function ClassRef:init(data)
    self.super.init(self, data)

    self._ui.Panel:addClickEventListener(function()
        executeFunc(self._onClick)
    end)

    self._avatarIconNode = AvatarIconNode.new(self._ui.Panel, "icon")
    self:refresh()
end

function ClassRef:refresh()
    if not self._data then return end
    self._endTime = self._data.time or 0

    self._avatarIconNode:update( self._data.userBaseInfo )
end

function ClassRef:updateTick(curTime)
    if not self:isVisible() then return end
    if not self._endTime then return end

    if self._endTime <= curTime then
        self._ui.Panel_mask:setVisible(false)
        self._endTime = nil
    else
        self._ui.Panel_mask:setVisible(true)
        self._ui.num:setString( self._endTime - curTime)
    end
end

function ClassRef:showTicket(visible)
    self._ui.ticket_null:setVisible(not visible)
end

function ClassRef:onBtnClick(cb)
    self._onClick = cb
end

return ClassRef
